package com.itheima.edu.info.manger.dao;

import com.itheima.edu.info.manger.domain.Teacher;

public class TeacherDao {
    private static Teacher[] teachers = new Teacher[5];

    public boolean addteacher(Teacher teacher) {
        int index = -1;
        for (int i = 0; i < teachers.length; i++) {
          Teacher  teache = teachers[i];//类型,变量名称接受下标
            if (teache== null) {
                index = i;//下标位置
                break;
            }
        }
        if (index == -1) {
            return false;
        } else {
            teachers[index] = teacher;
            return true;
        }

    }

    public Teacher[] findteacherid() {
        return teachers;
    }

    public void deleteid(String detid) {
        int index=getid(detid);
        teachers[index]=null;
      //获取索引ID位置
      //将索引位置用null表示
    }
    public  int getid(String id){
        int index=-1;
        for (int i = 0; i < teachers.length; i++) {
              Teacher teacher=teachers[i];
            if(teacher !=null && teacher.getId().equals(id)){
                index=i;
                break;
            }
        }
        return index;
    }

    public void updatasteacher(String uptid, Teacher newstu) {
        int index=getid(uptid);
         teachers[index]=newstu;
    }

    public Teacher[] findteacher() {
        return teachers;
    }
}
